package com.snsoft.ydsn.controller;

import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.snsoft.framework.web.IUrlDef;
import com.snsoft.ydsn.service.HomeService;
import com.snsoft.framework.web.controller.BaseController;

/*
 * 此代码由 "controller-gen" 生成，请不要修改. 
 * This class is generated by "controller-gen". 
 * Do not modify it.
 */

@Controller
@RequestMapping(IUrlDef.home)
public class HomeController extends BaseController {
    private static final String URL_NAME = "home";

    @Autowired
    private HomeService service;

    @RequestMapping(method = RequestMethod.GET)
    @ResponseBody
    public Object doGet(HttpServletRequest request,HttpServletResponse response, Model model
             ) throws InvocationTargetException {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put(REQUEST_KEY, request);
        params.put(RESPONSE_KEY, response);
        params.put(URL_NAME_KEY, URL_NAME);

        /* 重载 HTTP GET，根据QueryString中的method判断调用哪种方法。 */
        /* 注意：这里的方法都是“安全”的方法。即方法执行不会造成资源状态的变化。 */
        String method = request.getParameter(HTTP_METHOD_STR) == null ? "" : request.getParameter(HTTP_METHOD_STR);

        if (method.equalsIgnoreCase(HTTP_METHOD_HEAD)) {
            // HEAD
            return response(this.service, HTTP_METHOD_HEAD, params, model);
        } else if (method.equalsIgnoreCase(HTTP_METHOD_OPTIONS)) {
            // OPTIONS
            return response(this.service, HTTP_METHOD_OPTIONS, params, model);
        } else {
            // GET (default)
            return response(this.service, HTTP_METHOD_GET, params, model);
        }
    }
    @RequestMapping(method = RequestMethod.POST)
    @ResponseBody
    public Object doPost(HttpServletRequest request,HttpServletResponse response, Model model
             ) throws InvocationTargetException {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put(REQUEST_KEY, request);
        params.put(RESPONSE_KEY, response);
        params.put(URL_NAME_KEY, URL_NAME);

        /* 重载 HTTP POST，根据QueryString中的method判断调用哪种方法。 */
        /* 注意：put、post、delete都不是“安全”的。 */
        String method = request.getParameter(HTTP_METHOD_STR) == null ? "" : request.getParameter(HTTP_METHOD_STR);

        if (method.equalsIgnoreCase(HTTP_METHOD_PUT)) {
            // PUT
            return response(this.service, HTTP_METHOD_PUT, params, model);
        } else if (method.equalsIgnoreCase(HTTP_METHOD_DELETE)) {
            // DELETE
            return response(this.service, HTTP_METHOD_DELETE, params, model);
        } else {
            // POST (default)
            return response(this.service, HTTP_METHOD_POST, params, model);
        }
    }
}
